package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.Properties;

public class OracleRacTest {

    //数据库连接对象
    private static Connection conn = null;

    private static String driver = "oracle.jdbc.driver.OracleDriver"; //驱动

    //private static String url = "jdbc:oracle:thin:@//192.168.14.165:1521/orcl"; //连接字符串
    //private static String password = "1"; //密码
    private static String url = "jdbc:oracle:thin:@//192.168.11.104:1521/orcl"; //连接字符串
    private static String password = "123456"; //密码
    private static String username = "sys as sysdba"; //用户名


    public static void main(String[] args) throws SQLException {

        DriverManager.registerDriver(new com.mysql.jdbc.Driver());
        doQuery();
    }

    // 获得连接对象
    private static synchronized Connection getConn() {
        if (conn == null) {
            try {
                Class.forName(driver);
                conn = DriverManager.getConnection(url, username, password);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return conn;
    }

    private static void doQuery() {
        try (
            Connection conn = getConn();
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM SH.ORACLE_TEST3_quote");) {
            ResultSetMetaData rsmd = rs.getMetaData();
            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                String columnName = rsmd.getColumnName(i);
                Object columnType = rsmd.getColumnType(i);
                Boolean isCaseSensitive = rsmd.isCaseSensitive(i);
                System.out.println("columnName:" + columnName + ",columnType:" + columnType + ",isCaseSensitive:" + isCaseSensitive);
            }
            int type = Types.VARCHAR;
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
